package com.bamboo.framework.init;

import com.bamboo.model.SysStartLog;
import com.bamboo.service.SysStartLogService;
import com.bamboo.utils.GetComputerInfo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * Created by 20160988 on 2017/1/9.
 */
public class SysStartWork implements InitializingBean {

    protected Logger logger = LoggerFactory.getLogger(getClass());

    @Autowired
    SysStartLogService sysStartLogService;

    /**
     * 记录当前启动系统的服务器信息
     *
     * @throws Exception
     */
    @Override
    public void afterPropertiesSet() throws Exception {
        logger.info(">>>>>>>>>删除上次已触发未执行的TASK_任务");
        sysStartLogService.deleteJobLastTrriger();

        logger.info(">>>>>>>>>记录当前启动系统的服务器信息");
        SysStartLog sysStartLog = new SysStartLog();
        sysStartLog.setIp(GetComputerInfo.getIp());
        sysStartLog.setComputerName(GetComputerInfo.getComputerName());
        sysStartLog.setHostName(GetComputerInfo.getHostName());
        sysStartLog.setUserDomain(GetComputerInfo.getUserDomain());
        sysStartLog.setUserName(GetComputerInfo.getUserName());
        sysStartLog.setRemark("bamboo-Web启动成功");
        sysStartLogService.save(sysStartLog);
        System.out.println("====================================================");
        System.out.println("======       欢迎使用bamboo-web管理系统      ======");
        System.out.println("====================================================");
    }
}
